<template>
	<view class="box">
		<view class="address-btn" v-if="JSON.stringify(address) === '{}'">
			<button class="addressBtn" type="primary" size="mini" @click="chooseAddress">添加收货地址+</button>
		</view>

		<view class="address-info" @click="chooseAddress" v-else>
			<view class="row-info">
				<view class="username">名字：{{address.userName}}</view>
				<view class="content">
					<view class="phoneNum">手机：{{address.telNumber}}</view>
					<uni-icons type="right" size="25"></uni-icons>
				</view>
			</view>

			<view class="row-address">
				<text>收货地址：</text>
				<view class="address">{{addrStr}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {mapState,mapMutations,mapGetters} from 'vuex'
	
	export default {
		name: "my-address",
		data() {
			return {
			};
		},
		computed: {
			...mapState('m_address', ['address']),
			...mapGetters('m_address', ['addrStr'])
		},
		methods: {
			...mapMutations('m_address', ['updateAddress']),
			async chooseAddress() {
				const [err, success] = await uni.chooseAddress().catch(err => err)
				
				if (err === null && success.errMsg === 'chooseAddress:ok') {
					this.updateAddress(success)
				}
			}
		}
	}
</script>

<style lang="scss">
	.box {
		border-bottom: 6rpx solid #333333;

		.address-btn {

			height: 160rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			.addressBtn {
				width: 300rpx;
				height: 60rpx;
				line-height: 60rpx;
			}
		}

		.address-info {
			display: flex;
			flex-direction: column;
			justify-content: center;
			padding: 0 10rpx;

			.row-info {
				display: flex;
				justify-content: space-between;

				.content {
					display: flex;
					justify-content: space-between;
				}
			}

			.row-address {
				display: flex;
				align-items: center;
				margin: 20rpx 0;

				text {
					white-space: nowrap;
				}
			}
		}
	}
</style>
